package com.mdxx.xczd.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;

import java.util.List;

public class GsonUtil {
	static Gson gson = new Gson();
	public static <T> T jsonToBean(String result,Class<T> clazz){		
		T t = gson.fromJson(result, clazz);
		return t;		
	}

	public static String bean2json(Object obj){
		return gson.toJson(obj);
	}

	public static <T> List<T>  jsonToBeans(JSONArray optJSONArray,Class<T> clazz){		
		return gson.fromJson(optJSONArray.toString(), new TypeToken<List<T>>(){}.getType());
	}
}